package cn.tedu.ivos.base.response;

import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class JsonResult {
    /*
    1.内部状态码[必须有]
    2.状态码描述[必须有]
    3.具体数据[可能有也可能没有]
    */
    private Integer code;
    private String msg;
    private Object data;
    public JsonResult() {
    }

    /**
     * 应用场景：用于不需要返回具体数据的场景
     */
    public JsonResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    /**应用场景：所有需要返回具体数据的场景*/
    public JsonResult(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**应用场景：应用于没有具体数据返回的场景*/
    public JsonResult(StatusCode statusCode) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
    }
    /**应用场景：有具体数据返回的功能*/
    public JsonResult(StatusCode statusCode, Object data){
        this(statusCode);
        this.data = data;
    }
    /**应用场景：所有操作成功的功能*/
    public JsonResult(Object data) {
        this.code = StatusCode.SUCCESS.getCode();
        this.msg = StatusCode.SUCCESS.getMsg();
        this.data = data;
    }

    /**定义静态方法,用于快速生成 JsonResult 对象*/
    public static JsonResult ok(Object data){
        return new JsonResult(data);
    }
    /**定义静态方法,用于快速生成 JsonResult 对象*/
    public static JsonResult ok(){
        return ok(null);
    }
}